/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function loadDeleteDialogContent(emplID) {
    if (emplID !== null) {
        $.ajax({
            "url": 'a_load_empl_delete_dialog?id=' + emplID,
            "type": 'GET',
            "success": function (data) {
                document.getElementById('delete_confirm_dialog').innerHTML =
                    data;
            }
        });
    }
}

function deleteConfirmDialog() {
    var emplID = document.getElementsByClassName('row_selected')[0].id;
    $.Dialog({
        "title": "Увольнение",
        "draggable": true,
        "content": "<div id='delete_confirm_dialog'></div>",
        "onShow":loadDeleteDialogContent(emplID),
        "width": 500,
        "height": 130,
        "padding": 10

    });
}

function reloadTable()
{
    var oTable = document.getElementById("employee_table").dataTable;
    oTable.fnDraw();
}

function deleteEmployee() {
    var emplId = document.getElementById("emplId").value;

    $.ajax({
        "url": 'delete_employee',
        "type": 'POST',
        "data": {"emplId": emplId},
        "success": function () {
            $.Notify({
                "content": "Изменения приняты",
                "timeout": 5000,
                "style": {background: 'green', color: 'white'}
            });
            $.Dialog.close();
            reloadTable();
        },
        "error": function () {
            $.Notify({
                "content": "Изменения не приняты",
                "timeout": 5000,
                "style": {background: 'red', color: 'white'}
            });
            $.Dialog.close();
        }
    });
}
